//------------------------------------------------------------------------------
// X2D Game Engine
// Copyright (C) 2006-2007 Janusz Kowalski
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------

#include "SDL.h"
#include "RawVector.h"

#ifdef X2D_WITH_OPENGL
#ifdef OS_WINDOWS
#include <windows.h>
#endif
#include "GL/gl.h"
#include "GL/glu.h"
#endif

#ifndef IMGSDL_H
#define IMGSDL_H

// Load image from file.
// - colorkey - Add #FF00FF colorkey to the surface
// - optim - Optimise surface for the screen
SDL_Surface *loadImage(const char *path, bool colorkey, bool optim);

void getImageWH(const char *path, int &w, int &h);

#ifdef X2D_WITH_OPENGL
struct GLTex {
  GLuint tex; // OpenGL texture name.
  int w;  // Pixel width of the texture.
  int h;  // Pixel height of the texture.
};
#endif

// Image is not a resource. Only particular representation of it is.
class Image {
  private:
    union {
      SDL_Surface *surf;
#ifdef X2D_WITH_OPENGL
      GLTex *glTex;
#endif
    } data_;
  public:
    Image();
    Image(const char *path);
    // !! Compatibility reason. getSDLSurf is better name.
    // !! No mode checking.
    inline SDL_Surface* getSurf() {
      return data_.surf;
    }
#ifdef X2D_WITH_OPENGL
    inline GLuint getTex() {
      return data_.glTex->tex;
    }
#endif
    int getW();
    int getH();
    Image(const Image &src);
    Image& operator=(const Image &right);
    ~Image();
};

#endif
